package com.it135.citytraffic.controller;

import com.it135.citytraffic.pojo.entity.Survey;
import com.it135.citytraffic.pojo.result.Result;
import com.it135.citytraffic.pojo.vo.SurveyVO;
import com.it135.citytraffic.service.ISurveyService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 调查问卷
 */
@Slf4j
@RestController
@RequestMapping("/api/survey")
@RequiredArgsConstructor
public class SurveyController {
    // 注入服务
    private final ISurveyService surveyService;

    /**
     * 新增调查问卷填写信息
     *
     * @param surveyList
     * @return
     */
    @CrossOrigin
    @PostMapping
    public Result save(@RequestBody List<Survey> surveyList) {
        // 保存问卷
        surveyService.save(surveyList);
        return Result.success();
    }

    /**
     * 添加统计每个问题选项次数
     *
     * @return
     */
    @CrossOrigin
    @GetMapping
    public Result<String> queryCount() {
        // 统计每个问题选项次数
        String result = surveyService.queryCount();
        return Result.success(result);
    }

    /**
     * 添加词云
     *
     * @retur
     */
    @CrossOrigin
    @GetMapping("/wordCloud")
    public Result<SurveyVO> queryWordCloud() {
        // 添加词云
        SurveyVO surveyVO = surveyService.queryWordCloud();
        return Result.success(surveyVO);
    }

}

